package com.yyfax.common.form;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.yyfax.common.R;
import com.yyfax.common.form.interaction.ComplexTypeInteraction;
import com.yyfax.common.form.interaction.SimpleNormalInteraction;
import com.yyfax.common.form.interaction.SearchBarInteraction;
import com.yyfax.common.form.interaction.SimpleTypeInteraction;

import java.util.List;

/**
 * Created by fan on 2017/4/1.
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class SearchBar extends LinearLayout {
	private static final int SIMPLE_NORMAL = 1;
	private static final int COMPLEX_NORMAL = 2;
	private static final int SIMPLE_TYPE = 3;
	private static final int COMPLEX_TYPE = 4;
	/** 逾期一个月*/
	public static final int A_MONTH = 1;
	/** 逾期两个月*/
	public static final int TWO_MONTHS = 2;
	private int type;
	private SearchBarInteraction mSearchBarInteraction;

	public SearchBar(Context context) {
		super(context);
	}

	public SearchBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs);
	}

	public SearchBar(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context, attrs);

	}

	private void init(Context context, AttributeSet attrs) {
		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SearchBar);
		type = ta.getInt(R.styleable.SearchBar_type, 0);
		LayoutInflater inflater = LayoutInflater.from(context);
		View view;

		switch (type) {
			case SIMPLE_NORMAL:
				view = inflater.inflate(R.layout.search_bar_normal, this);
				mSearchBarInteraction = new SimpleNormalInteraction(context, ta, view);
				break;
			case SIMPLE_TYPE:
				view = inflater.inflate(R.layout.search_bar_type, this);
				mSearchBarInteraction = new SimpleTypeInteraction(context, ta, view);
				break;
			case COMPLEX_TYPE:
				view = inflater.inflate(R.layout.search_bar_type, this);
				mSearchBarInteraction = new ComplexTypeInteraction(context, ta, view);
				break;
		}
	}

	public void setFillSearchContent(boolean fillSearchContent) {
		mSearchBarInteraction.setFillSearchContent(fillSearchContent);
	}

	public void setShadow(View shadowView) {
		mSearchBarInteraction.setShadow(shadowView);
	}

	public void setSearchBarListener(SearchBarInteraction.SearchBarListener listener) {
		mSearchBarInteraction.setSearchBarListener(listener);
	}

	public void setSearchContent(int searchType, String content) {
		mSearchBarInteraction.setSearchContent(searchType, content);
	}

	public void setSearchContent(String content) {
		mSearchBarInteraction.setSearchContent(content);
	}

	/**
	 * 设置逾期类型
	 *
	 * @param type {@link #A_MONTH A_MONTH} ，{@link #TWO_MONTHS TWO_MONTHS} 。
	 * 其中A_MONTH为逾期一个月，TWO_MONTHS是逾期两个月 。默认{@link #A_MONTH A_MONTH}
	 */
	public void setOverdueType(int type) {
		mSearchBarInteraction.setOverdueType(type);
	}

	public void setSearchTypes(List<String> Types) {
				mSearchBarInteraction.setSearchTypes(Types);
	}

}
